package com.thinkit.bigdata.web.service.impl.audioSearch;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.thinkit.bigdata.web.model.result.HtmlResult;
import com.thinkit.bigdata.web.service.audioSearch.AudioSeaService;
import com.thinkit.bigdata.web.service.audioSearch.AudioSearchPubMet;
import com.thinkit.bigdata.web.service.impl.perCenter.perCenterServiceImpl;
import org.apache.log4j.Logger;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * Created by hccl on 2018/9/18.
 */
@Service
public class AudioSeaServiceImpl implements AudioSeaService {

    private static Logger logger = Logger.getLogger(perCenterServiceImpl.class);

    @Resource
    private AudioSearchPubMet searchPubMet;

    @Override
    public BoolQueryBuilder getQuery(String logTxt, HttpServletRequest request) {
        Map<String, String[]> params = new HashMap<>(request.getParameterMap());
        String provinceCode = request.getParameter("provinceCode");//省份
        if (!Strings.isNullOrEmpty(provinceCode)) {
            String customerlocs = request.getParameter("customerloc");//归属地
            params.put("customerloc", null);
            params.put("provinceCode", new String[]{JSON.toJSONString(searchPubMet.strFormatJson(provinceCode, customerlocs))});
        }
        return searchPubMet.getQuery(logTxt, params, request);
    }

    @Override
    public HtmlResult searchData(HttpServletRequest request) throws InvocationTargetException, IllegalAccessException {
        String logTxt = "【音频检索方法Impl】";
        logger.info(logTxt);
        Map<String, String[]> params = new HashMap<>(request.getParameterMap());
        String provinceCode = request.getParameter("provinceCode");//省份
        if (!Strings.isNullOrEmpty(provinceCode)) {
            String customerlocs = request.getParameter("customerloc");//归属地
            params.put("customerloc", null);
            params.put("provinceCode", new String[]{JSON.toJSONString(searchPubMet.strFormatJson(provinceCode, customerlocs))});
        }
        return searchPubMet.searchData(logTxt, params, request);
    }
}
